<template>
    <div class="fullScreen bg-c-wh">
        <!-- header、倒计时、玩法提示等 -->
        <lot-header></lot-header>
        <div class="scroll-lot tx-s-14" v-if="lotData != null">
            <!-- 两面盘 -->
            <div v-show="lotIndex == 0">
                <div class="title-lot">总和</div>
                <lhc-options :title="['', '']" :content="sflmpZh" :odds="lotOdds.zhdxdswds" :temp="4"></lhc-options>
                <div v-for="(item, i) in qqPlay" :key="i">
                    <div class="title-lot">{{ item[1] }}</div>
                    <lhc-options :title="[item[0], item[1]]" :content="sflmpDxds" :odds="lotOdds.zhdxdswds" :temp="4"></lhc-options>
                </div>
            </div>
            <!-- 单码 -->
            <div v-show="lotIndex > 0 && lotIndex < 9">
                <div class="title-lot">{{ qqCont[lotIndex][1] }}</div>
                <lhc-options :title="[qqCont[lotIndex][0], '']" :content="c1d20Cont" :odds="lotOdds.sz" :temp="6"></lhc-options>
                <div class="title-lot">两面</div>
                <lhc-options :title="[qqCont[lotIndex][0], '']" :content="sflmpDxds" :odds="lotOdds.zhdxdswds" :temp="4"></lhc-options>
                <div class="title-lot">方位/中发白</div>
                <lhc-options :title="[qqCont[lotIndex][0], '']" :content="zfbCont" :odds="lotOdds" :temp="4"></lhc-options>
            </div>
            <!-- 直选 -->
            <div v-show="lotIndex == 9">
                <lhc-cont-tab :title="'renx'" :tab="sfrxPlay"></lhc-cont-tab>
            </div>
        </div>
        <!-- footer -->
        <div class="flex-box flex-pj lotteryFooter tx-s-14">
            <div class="tx-c-r bor-r-g footer-btn" @click="cancel">重置</div>
            <div class="flex-box flex-f1">
                <input v-model="money" class="input-ol-n wd-fh tx-c" type="number" placeholder="请输入单注金额" />
            </div>
            <div class="tx-c-g bor-l-g footer-btn" @click="confirm">确定</div>
        </div> 
    </div>
</template>
<script type="text/ecmascript-6">
import 'common/css/lottery.css'
import { mapGetters } from 'vuex'
import { isDefine, isEmptyObject, openLotOrder } from '../../../common/js/common'
import Trans from '../../../common/js/eventTrans'
import LotHeader from "../../../components/lottery/lot-header"
import LhcContTab from "../../../components/lottery/lhcContTab"
import LhcOptions from "../../../components/lottery/lhcOptions"
import { qqPlay, sfrxPlay } from '../../../common/js/data'
import { sflmpZh, sflmpDxds, zfbCont, numCont } from '../../../common/js/data'
export default {
    data () {
        return {
            allResult : [],
            money : '',
            qqPlay : qqPlay(1, 8, ''), // 1到5球玩法
            sflmpZh : sflmpZh, // 两面盘总和内容
            zfbCont : zfbCont, // 中发白内容
            sflmpDxds : sflmpDxds, // 两面盘大小内容
            c1d11Cont : numCont(1, 11, ''), // 1-11内容
            c1d20Cont : numCont(1, 20, ''), // 1-20内容
            sfrxPlay : sfrxPlay, // 任选玩法
            qqCont : [
                ['', ''],
                ['d1q', '第一球'],
                ['d2q', '第二球'],
                ['d3q', '第三球'],
                ['d4q', '第四球'],
                ['d5q', '第五球'],
                ['d6q', '第六球'],
                ['d7q', '第七球'],
                ['d8q', '第八球'],
                ['', '']
            ]
        }
    },
    mounted () {
        var _this = this
        Trans.$on('togLotteryTab', function (msg) {
            _this.cancel()
        })
    },
    methods: {
        // 重置下注数据
        cancel () { 
            this.money = ''
            this.$store.state.lotOptTra = []
            this.$store.state.lotOptions = []
            this.$store.state.lotSelData = []
        },
        // 确定
        confirm () {
            const {lotStatus, lotSelData, lhcTra, lotTitle, lhcPlay} = this.$store.state
            if(lotStatus == 0){
                this.$alert('已封盘')
            }else if(lotStatus == -1){
                this.$alert('已关盘')
            }else if(isEmptyObject(lotSelData)){
                this.$toast('未下注', 2000)
            }else if(lotStatus == 1){
                if(lhcPlay > -1){
                    this.permutation(lotSelData)
                }else{
                    openLotOrder(this.money)
                }
            }
        },
        // 普通多选、复式数据重组
        permutation (data) {
            this.allResult = []
            const { lhcPlay } = this.$store.state
            if(data.length >= lhcPlay){
                this.combination(data, lhcPlay, [])
                this.$store.state.lotSelData = this.allResult
                openLotOrder(this.money)
            }else{
                this.$toast('所选内容未构成一注', 2000)
            }
        },
        // 递归组合数据
        combination (arr, size, result) {
            const arrLen = arr.length
            let selObj = ''
            if (size == arrLen) {
                const all = [].concat(result, arr)
                selObj = this.reData(all)
                this.allResult.push(selObj)
            } else {
                for (let i = 0 ; i < arrLen; i++) {
                    let newResult = [].concat(result)
                    newResult.push(arr[i])
                    if (size == 1) {
                        selObj = ''
                        selObj = this.reData(newResult)
                        this.allResult.push(selObj)
                    } else {
                        let newArr = [].concat(arr)
                        newArr.splice(0, i + 1)
                        this.combination(newArr, size - 1, newResult)
                    }
                }
            }
        },
        // 拼接递归数据
        reData (data) {
            let cont = data[0].content
            let name = data[0].name
            let odds = data[0].odds
            let selObj = ''
            const { lhcPlay } = this.$store.state
            for(let i = 0; i < data.length - 1; i++){
                let n = data[i+1]
                if(odds.indexOf('/') < 0 && n.odds < odds){
                    odds = n.odds
                }
                cont += ',' + n.content
                name += ',' + n.name
            }
            selObj = {
                'playType' : data[0].playType,
                'content' : cont,
                'odds' : odds,
                'name' : name,
                'nameT' : data[0].nameT,
                'issue' : this.lotData.countDown.issue
            }
            return selObj
        },
        // 打开玩法提示
        showDesc () {
            this.$store.state.lotDesc = true
        },
        sxCont () {
            return sxCont(1, '')
        }
    },
    components: {
        LotHeader,
        LhcContTab,
        LhcOptions
    },
    computed: {
        ...mapGetters([
            'lotData',
            'lotOdds',
            'lotIndex'
        ])
    }
};
</script>